﻿Namespace MapObjects

    Public Class SkyDome

        Private SDModel As MapObjects.Models
        Private SDModel2 As MapObjects.Models

        Public Sub New(Graphics As GraphicsDeviceManager, ContentDir As String)
            SDModel = New MapObjects.Models(Graphics, ContentDir)
            SDModel.ImportXFile("SkyDome\dome", 200)
            SDModel.ModelLocation = New Vector3(0, 0, 0)
            SDModel.SetStaticModelRotation(New Vector3(0, 0, 0))
            SDModel2 = New MapObjects.Models(Graphics, ContentDir)
            SDModel2.ImportXFile("SkyDome\dome2", 200)
            SDModel2.ModelLocation = New Vector3(0, 0, 0)
            SDModel2.SetStaticModelRotation(New Vector3(MathHelper.Pi, 0, 0))
        End Sub

        Public Sub Update(ServerTime As DateTime)
            Dim tmp1 As Vector4
            Dim tmp2 As Vector4
            Dim tmpMin As Long
            Dim redDiff As Single
            Dim greenDiff As Single
            Dim blueDiff As Single
            Dim red As Single
            Dim green As Single
            Dim blue As Single
            Dim C1 As Color
            Dim C2 As Color
            redDiff = Color.CornflowerBlue.R - Color.Black.R
            greenDiff = Color.CornflowerBlue.G - Color.Black.G
            blueDiff = Color.CornflowerBlue.B - Color.Black.B
            Select Case ServerTime.Hour
                Case 0, 1, 2, 3, 4, 20, 21, 22, 23
                    tmp1 = New Vector4(Color.Black.R, Color.Black.G, Color.Black.B, 1)
                    tmp2 = New Vector4(Color.Black.R, Color.Black.G, Color.Black.B, 1)
                    tmp1.X = (tmp1.X + red) / 255
                    tmp1.Y = (tmp1.Y + green) / 255
                    tmp1.Z = (tmp1.Z + blue) / 255
                    tmp2.X = (tmp2.X + red) / 255
                    tmp2.Y = (tmp2.Y + green) / 255
                    tmp2.Z = (tmp2.Z + blue) / 255
                Case 5, 6, 7
                    tmp1 = New Vector4(Color.Black.R, Color.Black.G, Color.Black.B, 1)
                    tmp2 = New Vector4(Color.Black.R, Color.Black.G, Color.Black.B, 1)
                    tmpMin = DateDiff(DateInterval.Minute, New DateTime(Now.Year, Now.Month, Now.Day, 5, 0, 0), ServerTime)
                    red = (redDiff / 180) * tmpMin
                    green = (greenDiff / 180) * tmpMin
                    blue = (blueDiff / 180) * tmpMin
                    tmp1.X = (tmp1.X + red) / 255
                    tmp1.Y = (tmp1.Y + green) / 255
                    tmp1.Z = (tmp1.Z + blue) / 255
                    tmp2.X = (tmp2.X + red) / 255
                    tmp2.Y = (tmp2.Y + green) / 255
                    tmp2.Z = (tmp2.Z + blue) / 255

                Case 8, 9, 10, 11, 12, 13, 14, 15, 16
                    tmp1 = New Vector4(Color.CornflowerBlue.R, Color.CornflowerBlue.G, Color.CornflowerBlue.B, 1)
                    tmp2 = New Vector4(Color.CornflowerBlue.R, Color.CornflowerBlue.G, Color.CornflowerBlue.B, 1)
                    tmp1.X = (tmp1.X + red) / 255
                    tmp1.Y = (tmp1.Y + green) / 255
                    tmp1.Z = (tmp1.Z + blue) / 255
                    tmp2.X = (tmp2.X + red) / 255
                    tmp2.Y = (tmp2.Y + green) / 255
                    tmp2.Z = (tmp2.Z + blue) / 255
                Case 17, 18, 19
                    tmp1 = New Vector4(Color.Black.R, Color.Black.G, Color.Black.B, 1)
                    tmp2 = New Vector4(Color.Black.R, Color.Black.G, Color.Black.B, 1)
                    tmpMin = DateDiff(DateInterval.Minute, New DateTime(Now.Year, Now.Month, Now.Day, 17, 0, 0), ServerTime)
                    red = (redDiff / 180) * (180 - tmpMin)
                    green = (greenDiff / 180) * (180 - tmpMin)
                    blue = (blueDiff / 180) * (180 - tmpMin)
                    tmp1.X = (tmp1.X + red) / 255
                    tmp1.Y = (tmp1.Y + green) / 255
                    tmp1.Z = (tmp1.Z + blue) / 255
                    tmp2.X = (tmp2.X + red) / 255
                    tmp2.Y = (tmp2.Y + green) / 255
                    tmp2.Z = (tmp2.Z + blue) / 255
            End Select
            SDModel.SkyDomeColor1 = tmp1
            SDModel.SkyDomeColor2 = tmp2
            SDModel2.SkyDomeColor1 = tmp1
            SDModel2.SkyDomeColor2 = tmp2
        End Sub

        Public Sub Draw(Device As GraphicsDevice, Effect As Effect, Camera As Cameras.FirstPerson, LightDirection As Vector3, LightAmbientValue As Single)
            SDModel.Draw(Device, Effect, Camera, LightDirection, LightAmbientValue, True)
            SDModel2.Draw(Device, Effect, Camera, LightDirection, LightAmbientValue, True)
        End Sub

        Public Sub DrawReflection(Device As GraphicsDevice, Effect As Effect, Camera As Cameras.FirstPerson, LightDirection As Vector3, LightAmbientValue As Single, WaterOffset As Single)
            SDModel.Draw(Device, Effect, Camera, LightDirection, LightAmbientValue, True, True, WaterOffset)
            SDModel2.Draw(Device, Effect, Camera, LightDirection, LightAmbientValue, True, True, WaterOffset)
        End Sub

    End Class

End Namespace